//
//  CentrelFriendView.swift
//  TianTianBiTing
//
//  Created by Gox mac 2 on 2019/3/6.
//  Copyright © 2019 Gox_WallyDiao. All rights reserved.
//

import UIKit

class CentrelFriendView: UIView {
    var image1:UIImageView = UIImageView()
    var image2:UIImageView = UIImageView()
    var image3:UIImageView = UIImageView()
    var label1:UILabel = UILabel()
    var label2:UILabel = UILabel()
    var label3:UILabel = UILabel()
    
    var model = [UserInfoModel]()
    var userModel: [UserInfoModel]? {
        didSet {
            guard let model = userModel else { return }
            self.model = model
            setData()
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.clear
        setUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setUI() {
        self.backgroundColor = RGB_Same(249)
        
        let width = SCREEN_WIDTH - 18
        
        self.image1 = UIImageView.init(frame: FRAME_CGFloat(width / 2 - 98, 14.5, 32, 32))
        self.image1.layer.cornerRadius = 16
        self.image1.layer.masksToBounds = true
        self.image1.image = IMAGE(name: "welfareFriend")
        self.addSubview(self.image1)
        
        self.image2 = UIImageView.init(frame: FRAME_CGFloat(width / 2 - 16, 14.5, 32, 32))
        self.image2.layer.cornerRadius = 16
        self.image2.layer.masksToBounds = true
        self.image2.image = IMAGE(name: "welfareFriend")
        self.addSubview(self.image2)
        
        self.image3 = UIImageView.init(frame: FRAME_CGFloat(width / 2 + 66, 14.5, 32, 32))
        self.image3.layer.cornerRadius = 16
        self.image3.layer.masksToBounds = true
        self.image3.image = IMAGE(name: "welfareFriend")
        self.addSubview(self.image3)
        
        self.label1 = UILabel.init(frame: FRAME_CGFloat(width / 2 - 123, 50.5, 82, 15))
        self.label1.font = Font_Medium(11)
        self.label1.textColor = RGB_Same(53)
        self.label1.textAlignment = .center
        self.addSubview(self.label1)
        
        self.label2 = UILabel.init(frame: FRAME_CGFloat(width / 2 - 41, 50.5, 82, 15))
        self.label2.font = Font_Medium(11)
        self.label2.textColor = RGB_Same(53)
        self.label2.textAlignment = .center
        self.addSubview(self.label2)
        
        self.label3 = UILabel.init(frame: FRAME_CGFloat(width / 2 + 41, 50.5, 82, 15))
        self.label3.font = Font_Medium(11)
        self.label3.textColor = RGB_Same(53)
        self.label3.textAlignment = .center
        self.addSubview(self.label3)
    }
  
    func setData() {
        switch self.model.count {
        case 1:
            self.label1.text = self.model[0].wxNickname
            self.image1.sd_setImage(with: URL(string:(StringIncludeChineseToString(self.model[0].wxAvatarUrl ?? ""))), placeholderImage: IMAGE(name: "welfarePlace"), options: .lowPriority, completed: nil)
        case 2:
            self.label1.text = self.model[0].wxNickname
            self.image1.sd_setImage(with: URL(string:(StringIncludeChineseToString(self.model[0].wxAvatarUrl ?? ""))), placeholderImage: IMAGE(name: "welfarePlace"), options: .lowPriority, completed: nil)
            self.label2.text = self.model[1].wxNickname
            self.image2.sd_setImage(with: URL(string:(StringIncludeChineseToString(self.model[1].wxAvatarUrl ?? ""))), placeholderImage: IMAGE(name: "welfarePlace"), options: .lowPriority, completed: nil)
        case 3:
            self.label1.text = self.model[0].wxNickname
            self.image1.sd_setImage(with: URL(string:(StringIncludeChineseToString(self.model[0].wxAvatarUrl ?? ""))), placeholderImage: IMAGE(name: "welfarePlace"), options: .lowPriority, completed: nil)
            self.label2.text = self.model[1].wxNickname
            self.image2.sd_setImage(with: URL(string:(StringIncludeChineseToString(self.model[1].wxAvatarUrl ?? ""))), placeholderImage: IMAGE(name: "welfarePlace"), options: .lowPriority, completed: nil)
            self.label3.text = self.model[2].wxNickname
            self.image3.sd_setImage(with: URL(string:(StringIncludeChineseToString(self.model[2].wxAvatarUrl ?? ""))), placeholderImage: IMAGE(name: "welfarePlace"), options: .lowPriority, completed: nil)
        default:
            return
        }
    }

}
